package com.robot.service.impl;

import com.robot.model.FireAlarm;
import com.robot.mapper.FireAlarmMapper;
import com.robot.service.FireAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FireAlarmServiceImpl implements FireAlarmService {
    
    @Autowired
    private FireAlarmMapper fireAlarmMapper;
    
    @Override
    public List<FireAlarm> getFireAlarms(String company, Integer year, Integer month) {
        if (month != null) {
            return fireAlarmMapper.findByCompanyAndYearAndMonth(company, year, month);
        } else {
            return fireAlarmMapper.findByCompanyAndYear(company, year);
        }
    }
    
    @Override
    public FireAlarm saveFireAlarm(FireAlarm fireAlarm) {
        fireAlarmMapper.insert(fireAlarm);
        return fireAlarm;
    }
    
    @Override
    public int getFireAlarmCount(String company, Integer year, Integer month) {
        List<FireAlarm> alarms = fireAlarmMapper.findByCompanyAndYearAndMonth(company, year, month);
        if (alarms.isEmpty()) {
            return 0;
        }
        return alarms.get(0).getCount();
    }
} 